import { create, update, remove, query } from '../../../../../framework/service/index';
import { ToastTips } from '../../../../../common/toastTips/tosat';
import { routerRedux } from 'dva/router';

export default {

  namespace: 'loginPassword',

  state: {
    date: [],
    oldLoginPassword: '123456'
  },

  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
        if(location.pathname === '/login-password') {
          // dispatch({
          //   type: 'query',
          // })
        }
      })
    },
  },



  effects: {
    *subRestPassword({ payload }, { call, put }) {

      const { oldPassword, newPassword} = payload;

      const { code, data, message } = yield call(create, '/api/oauth/reset_password', {
        oldPassword,
        newPassword
      });

      console.log('code',code);
      console.log('data',data);
      console.log('message',message);

      if(code == 200){
        ToastTips('修改成功', 2000, null);
        yield put(routerRedux.goBack())
      }else{
        ToastTips('修改失败', 2000, null);
      }
    }
  },

  reducers: {
    querySuccess(state, action) {
      return { ...state, ...action.payload };
    },
  }

};
